//
//  TestUITableViewSectionAdjustsView.m
//  MKUITestApp
//
//  Created by 苏尚进 on 2020/9/1.
//  Copyright © 2020 moon. All rights reserved.
//

#import "TestUITableViewSectionAdjustsView.h"

@implementation TestUITableViewSectionAdjustsView
- (id)initWithFrame:(CGRect)frame{
    if(self=[super initWithFrame:frame]){
        self.refreshButton = [[MKUIFlowLayoutButton alloc] init];
        [self.refreshButton addTarget:self action:@selector(__viewdidtap:) forControlEvents:UIControlEventTouchUpInside];
        [self.refreshButton setTitleColor:[UIColor systemBlueColor] forState:UIControlStateNormal];
        [self.refreshButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
        [self.refreshButton setTitle:@"Refresh" forState:UIControlStateNormal];
        self.refreshButton.contentInsets = UIEdgeInsetsMake(5, 5, 5, 5);
        [self.contentView addSubview:self.refreshButton];
        self.flowlayout = [[MKUISegmentFlowLayoutConstraint alloc] initWithItems:@[self.textLabel,self.refreshButton] constraintParam:(MKUISegmentFlowLayoutConstraint_H_C) contentInsets:[self.class contentMargin] interitemSpacing:10];
        self.flowlayout.boundaryItemIndex = 0;
        self.flowlayout.isLayoutPriorityFirstItems = NO;
    }
    return self;
}
- (void)layoutSubviews{
    [super layoutSubviews];
    CGRect bounds = self.bounds;
    self.flowlayout.bounds = bounds;
    [self.flowlayout layoutItemsWithResizeItems:YES];
}
- (CGSize)sizeThatFits:(CGSize)size{
    return [self.flowlayout sizeThatFits:CGSizeMake(size.width, 99999999) resizeItems:YES];
}
- (void)__viewdidtap:(id)sender{
    [self.sectionModel refreshWithAnimated:YES];
}
@end
